package com.yxx.sys.common;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: YuXinXin
 * @Description:
 * @Date:Created in 21:54 2020/8/13
 **/
public class TreeNodeBuilder {
  public static List<TreeNode> build(List<TreeNode> treeNodes, int pid) {
    List<TreeNode> treeNodeList=new ArrayList<>();
    for (TreeNode n1:treeNodes){
      if(n1.getParentId()==pid)
        treeNodeList.add(n1);
      for (TreeNode n2:treeNodes){
        if(n1.getId()==n2.getParentId())
          n1.getChildren().add(n2);
      }
    }
    return treeNodeList;
  }
}
